import BaseController from '../../core/controllers/Base.controller';

@Inject('$log', 'activityService', '$state', 'ngDialogService', 'disclosureService', 'trainingService', 'meetingService')
class toDoSafeActivitiesController extends BaseController {
  constructor() {
    super();

    this.view = {
      isDown: false, // 活动登记下拉收缩
      isTableLoading: false, // table数据加载状态，true：加载中，false：加载完
    };

    this.resource = {
      activityList: [],
    };

    this.mapParams = {};

    this.paginationService = this.activityService;

    this.$setQueryCallback((res) => {
      this.resource.activityList = res.rows;
    });

    this.query();
  }

  query() {
    this.$paginationQuery();
  }

  goEdit(activity) {
    if (activity.type === '1') {
      this.$state.go('technicalClarificaitonEdit', {
        id: activity.id,
      });
    }
    if (activity.type === '2') {
      this.$state.go('educationTrainingEdit', {
        id: activity.id,
      });
    }
    if (activity.type === '3') {
      this.$state.go('safeMeetingEdit', {
        id: activity.id,
      });
    }
  }

  goDetail(activity) {
    if (activity.type === '1') {
      this.$state.go('technicalClarificaitonDetail', {
        id: activity.id,
      });
    }
    if (activity.type === '2') {
      this.$state.go('educationTrainingDetail', {
        id: activity.id,
      });
    }
    if (activity.type === '3') {
      this.$state.go('safeMeetingDetail', {
        id: activity.id,
      });
    }
  }

  delete(activity) {
    switch (activity.type) {
      case '1':
        this.currentService = this.disclosureService;
        break;
      case '2':
        this.currentService = this.trainingService;
        break;
      case '3':
        this.currentService = this.meetingService;
        break;
      default:
        break;
    }
    this.ngDialogService.confirm('确定删除此数据吗？', activity)
      .then((data) => {
        this.currentService.delete([data.id])
        .then((res) => {
          if (res.success) {
            this.ngDialogService.alertError(res.message);
            this.query();
          } else {
            this.ngDialogService.alertError('删除失败');
          }
        });
      });
  }

  reset() {
    this.mapParams = {};
  }

}

export default toDoSafeActivitiesController;
